package com.tensquare.article.service;

import com.tensquare.article.dao.CommentDao;
import com.tensquare.article.pojo.Comment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import util.IdWorker;

import java.util.List;

/**
 * @author Alfred
 * @description TODO
 * @date 2021/4/26 17:40
 */
@Service
public class CommentService {
    @Autowired
    private CommentDao commentDao;
    @Autowired
    private IdWorker idWorker;

    /**
     * fetch data by rule id
     *
     * @description  查询全部
     * @param
     * @return
     */
    public List<Comment> findAll(){
        System.out.println(commentDao.findAll());
        return commentDao.findAll();
    }

    /**
     * fetch data by rule id
     *
     * @description  增加评论
     * @param
     * @return
     */
    public void add(Comment comment){
        comment.set_id(idWorker.nextId()+"");
        commentDao.save(comment);
    }

    /**
     * fetch data by rule id
     *
     * @description  根据文章ID查询评论列表
     * @param
     * @return
     */
    public List<Comment> findByArticleid(String articleid){
        return commentDao.findByArticleid(articleid);
    }
}
